package com.itheima.web;

import cn.hutool.http.HttpResponse;
import com.itheima.dto.mongo.PushMovementDto;
import com.itheima.servcie.CommentsService;
import com.itheima.servcie.MovementsService;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.lang.reflect.Array;

@RestController
@RequestMapping("/movements")
public class MovementsController {
    @Autowired
    private MovementsService movementsService;
    @Autowired
    private CommentsService commentsService;

    /**
     * 谁看过我
     */
    @GetMapping("/visitors")
    public ResponseEntity visitors(){
        return ResponseEntity.ok(movementsService.visitors());
    }

    /**
     * 查看个人所有动态
     * @param page
     * @param pagesize
     * @param userId
     * @return
     */
    @GetMapping("/all")
    private ResponseEntity getAllMyMovements(@RequestParam(defaultValue = "1") Integer page,
                                             @RequestParam(defaultValue = "10") Integer pagesize,
                                             Long userId){
        return ResponseEntity.ok(movementsService.getAllMyMovements(page, pagesize, userId));
    }

    /**
     * 查看好友动态
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping
    private ResponseEntity friendMovement(@RequestParam(defaultValue = "1") Integer page,
                                          @RequestParam(defaultValue = "10") Integer pagesize){
        return ResponseEntity.ok(movementsService.friendMovement(page, pagesize));
    }

    /**
     * 发布动态
     * @return
     */
    @PostMapping
    public ResponseEntity pushMovement(PushMovementDto pushMovementDto, MultipartFile imageContent[]){
        movementsService.pushMovement(pushMovementDto, imageContent);
        return ResponseEntity.ok(null);
    }

    /**
     * 推荐动态
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/recommend")
    public ResponseEntity recommend(@RequestParam(defaultValue = "1") Integer page,
                                    @RequestParam(defaultValue = "10") Integer pagesize){
        return ResponseEntity.ok(movementsService.recommend(page, pagesize));
    }

    /**
     * 获取单条动态信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseEntity movementInfo(@PathVariable String id){
        return ResponseEntity.ok(movementsService.movementInfo(id));
    }

    /**
     * 动态点赞
     * @param id
     * @return
     */
    @GetMapping("/{id}/like")
    public ResponseEntity like(@PathVariable ObjectId id) {
        return ResponseEntity.ok(commentsService.like(id));
    }

    /**
     * 取消点赞
     * @param id
     * @return
     */
    @GetMapping("/{id}/dislike")
    public ResponseEntity dislike(@PathVariable ObjectId id){
        return ResponseEntity.ok(commentsService.dislike(id));
    }

    /**
     * 动态喜欢
     * @param id
     * @return
     */
    @GetMapping("/{id}/love")
    public ResponseEntity love(@PathVariable String id){
        return ResponseEntity.ok(movementsService.love(id));
    }


    /**
     * 动态不喜欢
     * @param id
     * @return
     */
    @GetMapping("/{id}/unlove")
    public ResponseEntity unlove(@PathVariable String id){
        return ResponseEntity.ok(movementsService.unlove(id));
    }
}
